﻿using Volo.Abp.DependencyInjection;
using Volo.Abp.Users;
using YAPACS.Organizations;

namespace YAPACS.RisServer.Organizations;

public class CurrentUserOrganization(ICurrentUser currentUser) : ICurrentUserOrganization, ITransientDependency
{
    private readonly ICurrentUser _currentUser = currentUser;

    public Guid UserId
    {
        get => _currentUser.IsAuthenticated? _currentUser.Id.Value:default;
    }

    public Guid? UserGroupId
    {
        get
        {
            string userGroupId = _currentUser.FindClaimValue("user-group-id");
            return string.IsNullOrWhiteSpace(userGroupId) ? null : Guid.Parse(userGroupId);
        }
    }

    public Guid? DepartmentId
    {
        get
        {
            string departmentId = _currentUser.FindClaimValue("department-id");
            return string.IsNullOrWhiteSpace(departmentId) ? null : Guid.Parse(departmentId);
        }
    }

    public Guid? InstitutionId
    {
        get
        {
            string institutionId = _currentUser.FindClaimValue("institution-id");
            return string.IsNullOrWhiteSpace(institutionId) ? null : Guid.Parse(institutionId);
        }
    }
}
